package com.citicpub_cloud.restfull.dao;

import com.citicpub_cloud.restfull.dao.core.ContentTrack;
import com.citicpub_cloud.restfull.dao.core.EbookFile;
import com.citicpub_cloud.restfull.dao.jdbc.AbstractJdbcDaoSupport;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContentTrackDaoService extends AbstractJdbcDaoSupport {
    public List<ContentTrack> getContentTrackByAlbumId(Long albumId) {

        String sql = " SELECT t.* FROM content_track AS t " +
                " WHERE t.content_album_id = ? and t.is_delete=1 ORDER BY t.order_num ";
        List<ContentTrack> contentTrackList = jdbcTemplate.query(sql, new Object[]{albumId}, new BeanPropertyRowMapper(ContentTrack.class));
        return contentTrackList;
    }

    public  EbookFile getEbook(Long contentAlbumId){
        String sql = " SELECT file_url,file_size FROM content_album_ebook_file AS t " +
                " WHERE t.content_album_id = ? and t.is_delete=1 ";
        List<EbookFile> contentTrackList = jdbcTemplate.query(sql, new Object[]{contentAlbumId}, new BeanPropertyRowMapper(EbookFile.class));
        if(contentTrackList.size() > 0){
            return contentTrackList.get(0);
        }
        return null;
    }

}
